package com.zuxia.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zuxia.entity.Appointment;
import com.zuxia.uilt.PageModel;
import com.zuxia.service.IAppointmentService;

@Controller()
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/")
@Results({ 
	@Result(name = "selectApp", type = "dispatcher", location = "/admin/chaAppointment.jsp"), 
	@Result(name = "empty", type = "dispatcher", location = "/admin/empty.jsp"),
	@Result(name = "Y", type = "redirectAction", location = "/findAppointment"),
	@Result(name = "addOK", type = "dispatcher", location = "/index.jsp")
})
public class AppointmentAction extends ActionSupport implements
		ModelDriven<Appointment> {
	private static final long serialVersionUID = 1L;

	private Appointment appointment = new Appointment();

	public Appointment getModel() {
		return appointment;
	}

	@Autowired
	// ע��
	private IAppointmentService appservice;
	private int pageNo = 1;// ��̬�ı� ҳ��ȡ��
	private int pageSize = 5;// �̶�����
	private String yname="";
	private PageModel<?> pm ;
	
	
	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public PageModel<?> getPm() {
		return pm;
	}

	public void setPm(PageModel<?> pm) {
		this.pm = pm;
	}

	public String getYname() {
		return yname;
	}

	public void setYname(String yname) {
		this.yname = yname;
	}

	public Appointment getAppointment() {
		return appointment;
	}

	public void setAppointment(Appointment appointment) {
		this.appointment = appointment;
	}

	public IAppointmentService getAppservice() {
		return appservice;
	}

	public void setAppservice(IAppointmentService appservice) {
		this.appservice = appservice;
	}

	@Action("findAppointment")//��ѯԤԼ
	public String findAppointment() {
		pm = new PageModel();
    	List list = appservice.selectAppointment(pageNo,yname, pageSize);
		if(list.size()> 0){
			pm.setList(list);
			pm.setCount(appservice.appsize());
			pm.setPageNo(pageNo);
			pm.setPageSize(5);
			ActionContext.getContext().put("app", pm);
			int sumPage = pm.getSumPage();
			ActionContext.getContext().put("sumPage", sumPage);
			return "selectApp";
		}
		return "empty";
	}
	
	//ɾ��
	@Action("deleteAppointment")
	public String deleteAppointment() {
		appservice.delapp(appointment);
		return "Y";
	}
	
	//修改
	@Action("updateAppointment")
	public String updateAppointment(){
		appservice.updapp(appointment);
		return "Y";
	}
	//前台预约
	@Action("addAppointment")
	public String addAppointment(){
		appservice.addapp(appointment);
		return "addOK";
	}
}
